package com.luhuiguo.gwt.mvp.dispatcher.server;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.luhuiguo.gwt.mvp.dispatcher.client.StandardDispatcherService;
import com.luhuiguo.gwt.mvp.dispatcher.shared.exception.ActionException;
import com.luhuiguo.gwt.mvp.dispatcher.shared.exception.ServiceException;
import com.luhuiguo.gwt.mvp.dispatcher.shared.rpc.Action;
import com.luhuiguo.gwt.mvp.dispatcher.shared.rpc.Result;

/**
 * 
 * @author LuHuiguo
 * @version $Id: AbstractStandardDispatchServlet.java 6 2009-12-25 02:11:41Z
 *          luhuiguo $
 */
public abstract class AbstractDispatcherServlet extends RemoteServiceServlet implements StandardDispatcherService {

    private static final long serialVersionUID = -3596713818767496052L;

    public Result execute(Action<?> action) throws ActionException, ServiceException {
        try {
            return getDispatcher().execute(action);
        } catch (RuntimeException e) {
            log("Exception while executing " + action.getClass().getName() + ": " + e.getMessage(), e);
            throw new ServiceException(e);
        }
    }

    /**
     * 
     * @return The Dispatch instance.
     */
    protected abstract Dispatcher getDispatcher();

}
